package logic

import (
	"context"
	"post/docker/mysql"

	"post/postrpc/internal/svc"
	"post/postrpc/postrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ClassAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewClassAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClassAddLogic {
	return &ClassAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ClassAddLogic) ClassAdd(in *postrpc.ClassAddRequest) (*postrpc.ClassAddResponse, error) {
	// todo: add your logic here and delete this line

	class := mysql.Class{

		UserId:   in.UserId,
		Type:     in.Type,
		TypeName: in.Typename,
		Comment:  in.Comment,
	}
	mysql.DB.Debug().Create(&class)
	return &postrpc.ClassAddResponse{
		ClassId: int64(class.ID),
	}, nil
}
